﻿using System;
using System.Data;
using System.Configuration;
using System.Web;

using System.Text.RegularExpressions;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Collections;
using System.Net;

namespace UtilsBase
{
    /// <summary>
    /// 字符串处理
    /// </summary>
    public class UtilsStringQuery
    {
        public UtilsStringQuery()
        {
        }
        /// <summary>
        /// String TO GUID
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public Guid GetStringToGuid(string ID)
        {
            Guid userID = Guid.Empty;
            try
            {
                userID = new Guid(ID);
            }
            catch
            {
            }

            return userID;
        }
        /// <summary>
        /// 获取有效字符串
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        //public string GetString(string Text)
        //{
        //    return Text = Hack.SqlFilter(Text.Replace("'", "''").Trim());
        //}
        /// <summary>
        /// 数字小写转换(支持十位数以上数字转换)
        /// </summary>
        /// <param name="Num"></param>
        /// <returns></returns>
        public string ConvertNumToLower(long Num)
        {
            string strTmp = Num.ToString();
            string temp = strTmp;
            string result = "";
            for (int i = 0; i < strTmp.Length; i++)
            {
                result = result + ConvertNumToLowerSingle(int.Parse(temp.Substring(0, 1)), long.Parse(temp));
                result = result + UnitNumToLower(temp.Length - 1, long.Parse(temp));
                temp = temp.Substring(1, temp.Length - 1);
            }
            return result;
        }
        /// <summary>
        /// 数字小写转换(单个数字转换)
        /// </summary>
        /// <param name="ilen"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public string ConvertNumToLowerSingle(int Num, long total)
        {
            string strTmp = "";
            if (total > 0)
            {
                strTmp = Num.ToString();
                strTmp = strTmp.Replace("0", "○");
                strTmp = strTmp.Replace("1", "一");
                strTmp = strTmp.Replace("2", "二");
                strTmp = strTmp.Replace("3", "三");
                strTmp = strTmp.Replace("4", "四");
                strTmp = strTmp.Replace("5", "五");
                strTmp = strTmp.Replace("6", "六");
                strTmp = strTmp.Replace("7", "七");
                strTmp = strTmp.Replace("8", "八");
                strTmp = strTmp.Replace("9", "九");
            }
            return "" + strTmp.Trim() + "";
        }
        /// <summary>
        /// 数字单位小写转换
        /// </summary>
        /// <param name="ilen"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public string UnitNumToLower(int ilen, long total)
        {
            if (total.ToString().Length - 1 < ilen)
            {
                return "";
            }
            string str = "";
            string[] len = new string[17];
            len[0] = "十";
            len[1] = "百";
            len[2] = "千";
            len[3] = "万";
            len[4] = "十";
            len[5] = "百";
            len[6] = "千";
            len[7] = "亿";
            len[8] = "十";
            len[9] = "百";
            len[10] = "千";
            len[11] = "万";
            len[12] = "兆";
            len[13] = "十";
            len[14] = "百";
            len[15] = "千";
            len[16] = "万";
            if (ilen > 0 && ilen < len.Length)
            {
                str = len[ilen - 1];
            }
            return str;
        }
        /// <summary>
        /// 数字大写转换(支持十位数以上数字转换)
        /// </summary>
        /// <param name="Num"></param>
        /// <returns></returns>
        public string ConvertNumToUpper(long Num)
        {
            string strTmp = Num.ToString();
            string temp = strTmp;
            string result = "";
            for (int i = 0; i < strTmp.Length; i++)
            {
                result = result + ConvertNumToUpperSignle(int.Parse(temp.Substring(0, 1)), long.Parse(temp));
                result = result + UnitNumToUpper(temp.Length - 1, long.Parse(temp));
                temp = temp.Substring(1, temp.Length - 1);
            }
            return result;
        }
        /// <summary>
        /// 数字大写转换(单个数字转换)
        /// </summary>
        /// <param name="Num"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public string ConvertNumToUpperSignle(int Num, long total)
        {
            string strTmp = "";
            if (total > 0)
            {
                strTmp = Num.ToString();
                strTmp = strTmp.Replace("0", "零");
                strTmp = strTmp.Replace("1", "壹");
                strTmp = strTmp.Replace("2", "贰");
                strTmp = strTmp.Replace("3", "叁");
                strTmp = strTmp.Replace("4", "肆");
                strTmp = strTmp.Replace("5", "伍");
                strTmp = strTmp.Replace("6", "陆");
                strTmp = strTmp.Replace("7", "柒");
                strTmp = strTmp.Replace("8", "捌");
                strTmp = strTmp.Replace("9", "玖");
            }
            return "" + strTmp.Trim() + "";
        }
        /// <summary>
        /// 数字单位大写转换
        /// </summary>
        /// <param name="ilen"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public string UnitNumToUpper(int ilen, long total)
        {
            if (total.ToString().Length - 1 < ilen)
            {
                return "";
            }
            string str = "";
            string[] len = new string[17];
            len[0] = "拾";
            len[1] = "佰";
            len[2] = "仟";
            len[3] = "萬";
            len[4] = "拾";
            len[5] = "佰";
            len[6] = "仟";
            len[7] = "億";
            len[8] = "拾";
            len[9] = "佰";
            len[10] = "仟";
            len[11] = "萬";
            len[12] = "兆";
            len[13] = "十";
            len[14] = "百";
            len[15] = "千";
            len[16] = "万";
            if (ilen > 0 && ilen < len.Length)
            {
                str = len[ilen - 1];
            }

            return str;
        }

        /// <summary>
        /// 文章内容格式转换
        /// </summary>
        /// <param name="subjectstr"></param>
        /// <returns></returns>
        public string FormatContent(string subjectstr)
        {
            if (subjectstr != "" && subjectstr != null)
            {

                subjectstr = WebUtility.HtmlEncode(subjectstr);
                //subjectstr=subjectstr.Replace("&","&amp;");
                subjectstr = subjectstr.Replace("<", "&lt;");
                subjectstr = subjectstr.Replace(">", "&gt;");
                subjectstr = subjectstr.Replace(Convert.ToString((char)32), "&nbsp;");
                subjectstr = subjectstr.Replace("'", "'");
                //subjectstr=subjectstr.Replace("'","&quot;");
                subjectstr = subjectstr.Replace(Convert.ToString((char)13), "<br/>");
                subjectstr = subjectstr.Replace(Convert.ToString((char)10), "<p>");
                subjectstr = subjectstr.Replace("\r\n", "<p>");

            }
            return subjectstr;
        }
        /// <summary>
        /// 截取字符串
        /// </summary>
        /// <param name="inputString"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public string CutString(string Text, int len)
        {

            ASCIIEncoding ascii = new ASCIIEncoding();
            int tempLen = 0;
            string tempString = "";
            byte[] s = ascii.GetBytes(Text);
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 63)
                {
                    tempLen += 2;
                }
                else
                {
                    tempLen += 1;
                }

                try
                {
                    tempString += Text.Substring(i, 1);
                }
                catch
                {
                    break;
                }

                if (tempLen > len - 1)
                    break;
            }
            //如果截过则加上半个省略号
            byte[] mybyte = Encoding.Default.GetBytes(Text);
            if (mybyte.Length > len - 1)
                tempString += "...";

            return tempString;
        }
        /// <summary>
        /// 两日期天数比较
        /// </summary>
        /// <param name="DateTime1"></param>
        /// <param name="DateTime2"></param>
        /// <returns></returns>
        public string DateDiff(DateTime DateTime1, DateTime DateTime2)
        {
            int dateDiff = 0;
            try
            {
                TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
                TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
                TimeSpan ts = ts1.Subtract(ts2).Duration();
                dateDiff = ts.Days * 24 * 60 + ts.Hours * 60 + ts.Minutes;// "分钟"
                //  + ts.Seconds.ToString() +// "秒";
                // dateDiff = dateDiff / count;
            }
            catch
            {
                throw;
            }
            return dateDiff.ToString();
        }
        /// <summary>
        /// 随机码产生 4位
        /// </summary>
        /// <returns></returns>
        public string GetRandNumber()
        {
            return GetRandNumber(4);
        }
        /// <summary>
        /// 随机码产生2位
        /// </summary>
        /// <returns></returns>
        public string GetRandNumber2()
        {
            return GetRandNumber(2);
        }
        /// <summary>
        /// 随机码产生 位数自行设置 重载
        /// </summary>
        /// <returns></returns>
        public string GetRandNumber(int count)
        {
            char[] s = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
            string num = "";
            Random r = new Random(Guid.NewGuid().GetHashCode());//重要默认以时间作为种子，如果同时生成，随机码就相同
            for (int i = 0; i < count; i++)
            {
                num += s[r.Next(0, s.Length)].ToString();
            }
            return num;
        }

        /// <summary>
        /// 随机码产生 位数自行设置 重载
        /// </summary>
        /// <returns></returns>
        public string GetRandNumber(int count, int seed)
        {
            char[] s = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
            string num = "";
            Random r = new Random(seed);
            for (int i = 0; i < count; i++)
            {
                num += s[r.Next(0, s.Length)].ToString();
            }
            return num;
        }

        #region 字符串截取
        /// <summary>
        /// 设置每行字符串长度，不限制字符串长度
        /// </summary>
        /// <param name="str">待截取的字符串</param>
        /// <param name="len">每行的长度，多于这个长度自动换行</param>
        /// <returns></returns>
        public string CutRowsString(string Text, int len)
        {
            string s = "";

            for (int i = 0; i < Text.Length; i++)
            {
                int r = i % len;
                int last = Text.Length / len * len;
                if (i != 0 && i <= last)
                {

                    if (r == 0)
                    {
                        s += Text.Substring(i - len, len) + "<br/>";
                    }

                }
                else if (i > last)
                {
                    s += Text.Substring(i - 1);
                    break;
                }

            }

            return s;

        }

        /// <summary>
        /// 设置每行字符串长度，并限制字符串长度，多于给定的长度＋。。。
        /// </summary>
        /// <param name="str">待截取的字符串</param>
        /// <param name="len">每行的长度，多于这个长度自动换行</param>
        /// <param name="max">输出字符串最大的长度</param>
        /// <returns></returns>
        public string CutRowsString(string Text, int len, int max)
        {
            string s = "";
            string sheng = "";
            if (Text.Length > max)
            {
                Text = Text.Substring(0, max);
                sheng = "";
            }
            for (int i = 0; i < Text.Length; i++)
            {
                int r = i % len;
                int last = Text.Length / len * len;
                if (i != 0 && i <= last)
                {

                    if (r == 0)
                    {
                        s += Text.Substring(i - len, len) + "<br/>";
                    }

                }
                else if (i > last)
                {
                    s += Text.Substring(i - 1);
                    break;
                }

            }

            return s + sheng;

        }
        #endregion


        /// <summary>
        /// 去除HTML代码，纯文字（清除格式，图片）
        /// </summary>
        /// <param name="decryptString">截取文章内容时适合使用</param>
        /// <param name="str"></param>
        /// <returns></returns>
        public string HtmlToText(string Text)
        {
            //Text = Regex.Replace(Text, @"\<(img)[^>]*>|<\/(img)>", "", RegexOptions.IgnoreCase);
            Text = Text.ToLower();

            Text = Text.Replace("#", "");
            Text = Regex.Replace(Text, @"\<!--[^>]*>|<\/-->", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<form[\s\S]*?>", "", RegexOptions.IgnoreCase);
            Text = Text.Replace("</form>", "");
            Text = Text.Replace(Convert.ToString((char)13), "");
            Text = Text.Replace("\r\n", "");
            Text = Text.Replace(Convert.ToString((char)32), "");
            Text = Regex.Replace(Text, @"\<(img|table|tbody|tr|td|th)[^>]*>|<\/(img|table|tbody|tr|td|th)>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<(div|blockquote|fieldset|legend)[^>]*>|<\/(div|blockquote|fieldset|legend)>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<(font|i|u|h[1-9]|s)[^>]*>|<\/(font|i|u|h[1-9]|s)>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<(font|u|h[1-9]|s)[^>]*>|<\/(font|u|h[1-9]|s)>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<(style|strong|hr)[^>]*>|<\/(style|strong|p)>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<a[^>]*>|<\/a>|<wbr>", "", RegexOptions.IgnoreCase);
            Text = Text.Replace("<br>", "");
            Text = Regex.Replace(Text, @"\<(&)[^;]*>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<b[>]*>|<\/b>|<b[^r]*[^>]>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<(meta|iframe|frame|span|tbody|layer)[^>]*>|<\/(iframe|frame|meta|span|tbody|layer)>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<p[\s\S]*?>", "<br/>", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<b[\s\S]*?>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\&[^;]*;", "", RegexOptions.IgnoreCase);
            // Text = Text.Replace("&nbsp;", "");
            // Text = Regex.Replace(Text, @"\<br[^>]*", "", RegexOptions.IgnoreCase);
            // Text = Regex.Replace(Text, @"(?is)(?<!<p>((?!</p>).)*)<p>", "", RegexOptions.IgnoreCase);
            // Text = Regex.Replace(Text, @"(?is)(?<!<p>((?!</p>).)*)</p>", "", RegexOptions.IgnoreCase);
            //  Text = Regex.Replace(Text, @"([a-zA-Z]+?)=([^" + "\"" + @"]+?)(?=>)", "", RegexOptions.IgnoreCase);//去掉不规则属性定义如<p align=left>
            //Text = Regex.Replace(Text, @"(?<=(img)[^>]*?)(?<content>\S*=(?!" + "\"" + @"))(?<Content2>[^>|\s]*)(?=.*>)", "", RegexOptions.IgnoreCase);//去掉不规则属性定义如<p align=left>

            ////---------------------去掉&开始;结束的格式符号代码
            //MatchCollection matc = Regex.Matches(Text, @"&[^;]*;", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            //foreach (Match mat in matc)
            //{
            //    Text = Text.Replace(mat.Groups[0].Value, "");
            //}
            //---------------------处理图片没有正常结束的标签
            MatchCollection matc = Regex.Matches(Text, @"<(img)[^>]*[^/]>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            foreach (Match mat in matc)
            {
                Text = Text.Replace(mat.Groups[0].Value, mat.Groups[0].Value.Trim().Replace(">", "") + @"/>");
            }


            Text = Text.Replace("<br/>", "").Trim();
            matc = null;

            return Text;

        }

        /// <summary>
        /// WEB文章内容转为WAP显示（清除不必要或WAP不兼容的格式，保留图片显示）
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string HtmlToWap(string Text)
        {

            //Text = Regex.Replace(Text, @"\<(img)[^>]*>|<\/(img)>", "", RegexOptions.IgnoreCase);
            Text = Text.ToLower();
            Text = Regex.Replace(Text, @"\<(table|tbody|tr|td|th)[^>]*>|<\/(table|tbody|tr|td|th)>", "", RegexOptions.IgnoreCase);
            //Text = Regex.Replace(Text, @"\<(div|blockquote|fieldset|legend)[^>]*>|<\/(div|blockquote|fieldset|legend)>", "", RegexOptions.IgnoreCase);
            //Text = Regex.Replace(Text, @"\<(font|i|u|h[1-9]|s)[^>]*>|<\/(font|i|u|h[1-9]|s)>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<(font|u|h[1-9]|s)[^>]*>|<\/(font|u|h[1-9]|s)>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<(style|strong|hr)[^>]*>|<\/(style|strong|p)>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<a[^>]*>|<\/a>|<wbr>", "", RegexOptions.IgnoreCase);
            Text = Text.Replace("<br>", "<br/>");
            Text = Regex.Replace(Text, @"\<b[>]*>|<\/b>|<b[^r]*[^>]>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<(meta|iframe|frame|span|tbody|layer)[^>]*>|<\/(iframe|frame|meta|span|tbody|layer)>", "", RegexOptions.IgnoreCase);
            Text = Regex.Replace(Text, @"\<p[\s\S]*?>", "<br/>", RegexOptions.IgnoreCase);
            // Text = Regex.Replace(Text, @"\<br[^>]*", "", RegexOptions.IgnoreCase);
            // Text = Regex.Replace(Text, @"(?is)(?<!<p>((?!</p>).)*)<p>", "", RegexOptions.IgnoreCase);
            // Text = Regex.Replace(Text, @"(?is)(?<!<p>((?!</p>).)*)</p>", "", RegexOptions.IgnoreCase);
            //  Text = Regex.Replace(Text, @"([a-zA-Z]+?)=([^" + "\"" + @"]+?)(?=>)", "", RegexOptions.IgnoreCase);//去掉不规则属性定义如<p align=left>
            Text = Regex.Replace(Text, @"(?<=(img)[^>]*?)(?<content>\S*=(?!" + "\"" + @"))(?<Content2>[^>|\s]*)(?=.*>)", "", RegexOptions.IgnoreCase);//去掉不规则属性定义如<p align=left>
            //---------------------处理图片没有正常结束的标签
            MatchCollection matc = Regex.Matches(Text, @"<(img)[^>]*[^/]>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            foreach (Match mat in matc)
            {
                Text = Text.Replace(mat.Groups[0].Value, mat.Groups[0].Value.Trim().Replace(">", "") + @"/>");
            }
            matc = Regex.Matches(Text, @"(?<=<img[^>]*src=" + "\"" + @"(?!http))(?<Content>[\s\S]*?)(?=" + "\"" + @"[\S\s]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            foreach (Match mat in matc)
            {
                Text = Text.Replace(mat.Groups["Content"].Value, @"http://www.iyachi.com/" + @mat.Groups["Content"].Value.TrimStart('/').Replace("http://www.iyachi.com/", "1"));
            }

            matc = null;

            return Text;

        }


        // （1）SQL Server中SQL命令实现这一思路的方式：
        //DECLARE @aGuid UNIQUEIDENTIFIER 
        //SET @aGuid = CAST(CAST(NEWID() AS BINARY(10))+ CAST(GETDATE() AS BINARY(6)) AS UNIQUEIDENTIFIER)
        //（2）实现COMB数据的C#方式：
        ///<summary>
        /// 返回 GUID 用于数据库操作，特定的时间代码可以提高检索效率
        /// </summary>
        /// <returns>COMB (GUID 与时间混合型) 类型 GUID 数据</returns>
        public Guid NewComb()
        {
            byte[] guidArray = Guid.NewGuid().ToByteArray();
            DateTime baseDate = new DateTime(1900, 1, 1);
            DateTime now = DateTime.Now;
            // Get the days and milliseconds which will be used to build the byte string 
            TimeSpan days = new TimeSpan(now.Ticks - baseDate.Ticks);
            TimeSpan msecs = new TimeSpan(now.Ticks - new DateTime(now.Year, now.Month, now.Day).Ticks);
            // Convert to a byte array 
            // Note that SQL Server is accurate to 1/300th of a millisecond so we divide by 3.333333 
            byte[] daysArray = BitConverter.GetBytes(days.Days);
            byte[] msecsArray = BitConverter.GetBytes((long)(msecs.TotalMilliseconds / 3.333333));
            // Reverse the bytes to match SQL Servers ordering 
            Array.Reverse(daysArray);
            Array.Reverse(msecsArray);
            // Copy the bytes into the guid 
            Array.Copy(daysArray, daysArray.Length - 2, guidArray, guidArray.Length - 6, 2);
            Array.Copy(msecsArray, msecsArray.Length - 4, guidArray, guidArray.Length - 4, 4);
            return new Guid(guidArray);
        }
        /// <summary>
        /// 从 SQL SERVER 返回的 GUID 中生成时间信息
        /// </summary>
        /// <param name="guid">包含时间信息的 COMB </param>
        /// <returns>时间</returns>
        public DateTime GetDateFromComb(Guid guid)
        {
            DateTime baseDate = new DateTime(1900, 1, 1);
            byte[] daysArray = new byte[4];
            byte[] msecsArray = new byte[4];
            byte[] guidArray = guid.ToByteArray();
            // Copy the date parts of the guid to the respective byte arrays. 
            Array.Copy(guidArray, guidArray.Length - 6, daysArray, 2, 2);
            Array.Copy(guidArray, guidArray.Length - 4, msecsArray, 0, 4);
            // Reverse the arrays to put them into the appropriate order 
            Array.Reverse(daysArray);
            Array.Reverse(msecsArray);
            // Convert the bytes to ints 
            int days = BitConverter.ToInt32(daysArray, 0);
            int msecs = BitConverter.ToInt32(msecsArray, 0);
            DateTime date = baseDate.AddDays(days);
            date = date.AddMilliseconds(msecs * 3.333333);
            return date;
        }
        /// <summary>
        /// 日期转换成unix时间戳
        /// </summary>
        /// <param name=dateTime></param>
        /// <returns></returns>
        public long DateTimeToUnixTimestamp(DateTime dateTime)
        {
            var start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local);
            return Convert.ToInt64((dateTime - start).TotalSeconds);
        }

        /// <summary>
        /// unix时间戳转换成日期
        /// </summary>
        /// <param name=unixTimeStamp>时间戳（秒）</param>
        /// <returns></returns>
        public DateTime UnixTimestampToDateTime(long timestamp)
        {
            var start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local);
            return start.AddSeconds(timestamp);
        }
        /// <summary>
        /// 转入Text,输出json字符串
        /// </summary>
        /// <param name="Text"></param>
        /// <returns></returns>
        public string ConvertTextToJsonStr_HtmlContent(string Text)
        {


            string returnvalue = Text.Replace("\r\n", "\\r\\n").Replace("\t", " ").Replace("\"", "\\\"");
            // returnvalue = Text.ToString().Replace("\\", "\\\\").Replace("\'", "\\\'").Replace("\t", " ").Replace("\"", "'");
            return returnvalue;
        }

        public string ConvertTextToJsonStr(string Text)
        {


            string returnvalue = Text.Replace("\r\n", "\\r\\n").Replace("\t", " ").Replace("\"", "\\\"").Replace("\\", "\\\\");
            // returnvalue = Text.ToString().Replace("\\", "\\\\").Replace("\'", "\\\'").Replace("\t", " ").Replace("\"", "'");
            return returnvalue;
        }
        /// <summary>
        /// 小数点
        /// </summary>
        /// <returns></returns>
        public double NumRound(double num, int length)
        {
            return Math.Round(num, length);   //Returns   45.37
        }


        #region 秒转换小时 SecondToHour
        /// <summary>
        /// 秒转换小时
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static string SecondToHour(double time)
        {
            if (time == 0) return "";
            //  string str = "";
            int hour = 0;
            int minute = 0;
            int second = 0;
            second = Convert.ToInt32(time);

            if (second > 60)
            {
                minute = second / 60;
                second = second % 60;
            }
            if (minute > 60)
            {
                hour = minute / 60;
                minute = minute % 60;
            }

            string strhour = hour.ToString();
            if (hour < 10)
            {
                strhour = "0" + strhour;
            }

            string strminute = minute.ToString();
            if (minute < 10)
            {
                strminute = "0" + strminute;
            }

            string strsecond = second.ToString();
            if (second < 10)
            {
                strsecond = "0" + strsecond;
            }

            return strhour + ":" + strminute + ":"
                + strsecond + "";
        }
        #endregion
    }


}


